/*
** my_showstr.c for my_showstr in /home/goupil_r//afs/Jour_06
** 
** Made by robin goupil
** Login   <goupil_r@epitech.net>
** 
** Started on  Tue Oct  9 14:45:51 2012 robin goupil
** Last update Sun Nov 18 10:05:41 2012 robin goupil
*/

void	show_special_char(char c, char *base)
{
  int	nbr;
  int	i;
  int	j;
  char	result[32];
  int	base_size;

  i = -1;
  base_size = my_strlen(base);
  my_putchar('\\');
  while (c > 0)
    {
      result[++i] = base[c % base_size];
      c = (c - (c % base_size)) / base_size;
    }
  j = i;
  while (j++ < 2)
    my_putchar(base[0]);
  while (i >= 0)
    my_putchar(result[i--]);
}

int	my_showstr(char *str, char *base)
{
  int	i;

  i = 0;
  while (str[i])
    {
      if (str[i] < 32 || str[i] > 126)
	show_special_char(str[i], base);
      else
	my_putchar(str[i]);
      i = i + 1;
    }
  return (0);
}
